package cn.gok.manage.web;

import cn.gok.manage.service.IProductService;
import cn.gok.pojo.Product;
import cn.gok.util.ResultData;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author: 鸭鸭
 * @ClassName:ProductController
 * @Package:cn.gok.gokhappymall.manage.web
 * @Description:
 * @date: 2021/8/3
 * @time: 16:37
 */
@Controller
@RequestMapping("/manage/product/")
public class ProductController {
    @Autowired
    IProductService productService;

    @ResponseBody
    @RequestMapping("list.do")
    public ResultData getAllProducts(@RequestParam(defaultValue = "1")int pageNum,
                                     @RequestParam(defaultValue = "10") int pageSize){

        return productService.getAllProducts(pageNum,pageSize);

    }


    @ResponseBody
    @RequestMapping("search.do")
    public ResultData getProductsByIdAndName(Integer id,String name){
        return productService.getProductsByIdAndName(id,name);
    }



    @RequestMapping("/upload.do")
    public ResultData uploadPhoto(@RequestParam(value = "upload_file") MultipartFile mf, String desc, HttpServletRequest httpServletRequest)  {
        return  productService.updatePhoto(mf,desc,httpServletRequest);
    }


    @ResponseBody
    @RequestMapping("detail.do")
    public ResultData getProductById(Integer id){
        return productService.getProducttById(id);
    }


    @ResponseBody
    @RequestMapping("set_sale_status.do")
    public ResultData updateProductStatus(Integer id, Integer status){
        return productService.updateProductStatus(id,status);
    }

    @ResponseBody
    @RequestMapping("save.do")
    public ResultData insert(Product product){
        return productService.insert_Product(product);
    }

    /*
    * 产品搜索及动态排序List
    * */
    @ResponseBody
    @RequestMapping("keyList.do")
    public ResultData selectProductsByKeyword(@RequestParam(value="categoryId") int categoryId,
                                              @RequestParam(value="keyword",required = false,defaultValue = "") String keyword,
                                              @RequestParam(value="pageSize",required = false,defaultValue = "10") int pageSize,
                                              @RequestParam(value="pageNum",required = false,defaultValue = "1") int pageNum,
                                              @RequestParam(value="orderBy",required = false,defaultValue = "") String orderBy){
        return productService.selectProductByKeyWord(keyword,categoryId,pageNum,pageSize,orderBy);

    }
}
